﻿@model AddToCartModel
@{
    string text = "";
    if (Model.CartType == ShoppingCartType.ShoppingCart)
    {
        text = string.Format(T("AddToCart.Cart.Items").Text, Model.TotalItems);
    }
    else if (Model.CartType == ShoppingCartType.Wishlist)
    {
        text = string.Format(T("AddToCart.Wishlist.Items").Text, Model.TotalItems);
    }
    else if (Model.CartType == ShoppingCartType.Auctions)
    {
        text = string.Format(T("Addtocart.Auctions.Ongoing").Text, Model.TotalItems);
    }
}
@await Component.InvokeAsync("Widget", new { widgetZone = "popup_add_to_cart_content_before", additionalData = Model })
<div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content rounded-0 p-2 p-xl-3">
        <div class="modal-header bg-info rounded-0">
            <h5 class="text-center text-white w-100 mb-0">
                @if (Model.CartType == ShoppingCartType.ShoppingCart || Model.CartType == ShoppingCartType.OnHoldCart)
                {
                    @T("AddToCart.ShoppingCart")
                }
                else if (Model.CartType == ShoppingCartType.Wishlist)
                {
                    @T("AddToCart.Wishlist")
                }
                else if (Model.CartType == ShoppingCartType.Auctions)
                {
                    @T("shoppingcart.yourbidhasbeenplaced")
                }
            </h5>
            <button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
                <span class="mdi mdi-close"></span>
            </button>
        </div>
        <div class="modal-body px-0 pt-xl-3 pt-2 pb-0">
            <div class="col-12">
                <div class="row">
                    <div class="col-md-3 col-12 mb-xl-3 mb-2 d-none d-md-block pl-0">
                        <img class="img-fluid" alt="@Model.Picture.AlternateText" src="@Model.Picture.ImageUrl" title="@Model.Picture.Title" />
                    </div>
                    <div class="col-md-9 col-12 mb-xl-3 mb-2 modal-border d-flex">
                        <div class="row">
                            <div class="form-group mb-0">
                                <h4 class="mb-0">
                                    <a href="@Url.RouteUrl("Product", new { SeName = Model.ProductSeName })" class="text-center">@Model.ProductName</a>
                                </h4>
                            </div>
                            @if (!string.IsNullOrEmpty(Model.AttributeDescription))
                            {
                                <div class="form-group col-12 px-0 d-none d-md-block my-2">
                                    <label class="w-100 mb-0"><strong>@T("AddToCart.Attributes")</strong></label>
                                    <div class="attributes">
                                        @Html.Raw(Model.AttributeDescription)
                                    </div>
                                </div>
                            }
                            @if (!string.IsNullOrEmpty(Model.ReservationInfo))
                            {
                                <div class="form-group col-12 px-0 d-none d-md-block">
                                    <label class="w-100"><strong>@T("AddToCart.ReservationInfo")</strong></label>
                                    <div class="attributes">
                                        @Html.Raw(Model.ReservationInfo)
                                    </div>
                                </div>
                            }
                            @if (!Model.IsAuction)
                            {
                                <div class="form-group col-12 pl-0 mb-0 d-flex">
                                    <label class="mb-0"><strong>@T("AddToCart.Qty")</strong></label>
                                    <label class="pl-3 mb-0">@Model.Quantity</label>
                                </div>
                            }
                            else
                            {
                                <div class="form-group col-12 pl-0 mb-0 d-flex">
                                    @if (Model.EndTime.HasValue)
                                    {
                                        <div>
                                            @if (Model.EndTime > DateTime.UtcNow)
                                            {
                                                <label class="d-inline-block">@T("AddToCart.Timeleft"): </label>
                                                <div class="d-inline-block" id="popupEndTime" data-countdown="@Model.EndTime.Value.ToString("yyyy-MM-dd HH:mm UTC")"></div>
                                            }
                                            else
                                            {
                                                <label>@T("ShoppingCart.Auctionends"): @Model.EndTime.Value.ToString()</label>
                                            }
                                        </div>
                                        <script asp-location="Footer">
                                            $(document).ready(function () {
                                                var cd = $('#popupEndTime');
                                                var finalDate = cd.data('countdown');
                                                cd.countdown(finalDate, function (event) {
                                                    if (event.strftime('%D') > 0) {
                                                        cd.html(event.strftime('%D days %H:%M:%S'));
                                                    }
                                                    else {
                                                        cd.html(event.strftime('%H:%M:%S'));
                                                    }
                                                });
                                            });
                                        </script>
                                    }
                                </div>
                            }

                            <div class="form-group col-12 pl-0 mb-1 d-flex">
                                @if (Model.IsAuction)
                                {
                                    <label class=""><strong>@T("AddToCart.Yourbid"):</strong></label>
                                    <label class="pl-3 mb-0">@Model.HighestBid</label>
                                }
                                else
                                {
                                    <label class=""><strong>@T("AddToCart.Price")</strong></label>
                                    <label class="pl-3 mb-0">@Model.Price</label>
                                }
                            </div>
                            <div class="text-center modal-padding-off d-sm-block d-none w-100 p-3">
                                <h5 class="w-100 mb-0">@text</h5>
                                @if (!string.IsNullOrEmpty(Model.SubTotalDiscount))
                                {
                                    <div class="form-group mb-1 d-flex justify-content-center">
                                        <label class="text-muted mb-0">@T("AddToCart.SubTotalDiscount")</label>
                                        <label class="pl-3 mb-0 text-muted">@Model.SubTotalDiscount</label>
                                    </div>
                                }
                                @if (!string.IsNullOrEmpty(Model.SubTotal))
                                {
                                    <div class="form-group mb-0 d-flex justify-content-center">
                                        <label class="text-dark mb-0">@T("AddToCart.SubTotal")</label>
                                        <label class="pl-3 mb-0 text-dark mb-0">@Model.SubTotal</label>
                                    </div>
                                }
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal-footer pt-xl-3 pt-2 px-0 pb-0">
                <div class="btn-group offset-md-5 col-md-7 col-12 px-0">
                    @if (Model.CartType == ShoppingCartType.Auctions)
                    {
                        <button type="button" class="btn btn-outline-info w-100 text-uppercase mr-1 d-flex justify-content-center" onclick="javascript:window.location.reload()" data-dismiss="modal">@T("AddToCart.Continue")</button>
                    }
                    else
                    {
                        <button type="button" class="btn btn-outline-info w-100 text-uppercase mr-1 d-flex justify-content-center" data-dismiss="modal">@T("AddToCart.Continue")</button>
                    }
                    @if (Model.CartType == ShoppingCartType.ShoppingCart || Model.CartType == ShoppingCartType.OnHoldCart)
                    {
                        <button type="button" class="btn btn-info w-100 d-flex justify-content-center text-uppercase ml-0 border-left-0" onclick="setLocation('@(Url.RouteUrl("ShoppingCart"))')">@T("AddToCart.ViewCart")</button>
                    }
                    else if (Model.CartType == ShoppingCartType.Wishlist)
                    {
                        <button type="button" class="btn btn-info w-100 d-flex justify-content-center text-uppercase ml-0 border-left-0" onclick="setLocation('@(Url.RouteUrl("Wishlist"))')">@T("AddToCart.ViewWishlist")</button>
                    }
                    else if (Model.CartType == ShoppingCartType.Auctions)
                    {
                        <button type="button" class="btn btn-info w-100 d-flex justify-content-center text-uppercase ml-0 border-left-0" onclick="setLocation('@(Url.RouteUrl("CustomerAuctions"))')">@T("AddToCart.ViewAuctions")</button>
                    }
                </div>
            </div>
            @await Component.InvokeAsync("CrossSellProducts")
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        $("#ModalAddToCart .cross-sell-container .btn-quick-view").on("click", function () {
            $('#ModalAddToCart').modal('hide');
        });
    });
</script>
